/**
 * There are code generation
 */
package com.neusoft.lohas.modules.ivm.service.order;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.neusoft.lohas.common.persistence.Page;
import com.neusoft.lohas.common.service.BaseService;
import com.neusoft.lohas.common.utils.StringUtils;
import com.neusoft.lohas.modules.ivm.entity.order.DeliveryInfo;
import com.neusoft.lohas.modules.ivm.dao.order.DeliveryInfoDao;

/**
 * 送货单信息Service
 * @author Jackie.Liu
 * @version 2014-12-23
 */
@Component
@Transactional(readOnly = true)
public class DeliveryInfoService extends BaseService {

	@Autowired
	private DeliveryInfoDao deliveryInfoDao;
	
	public DeliveryInfo get(String id) {
		return deliveryInfoDao.get(id);
	}
	
	public Page<DeliveryInfo> find(Page<DeliveryInfo> page, DeliveryInfo deliveryInfo) {
		DetachedCriteria dc = deliveryInfoDao.createDetachedCriteria();
		if (StringUtils.isNotEmpty(deliveryInfo.getName())){
			dc.add(Restrictions.like("name", "%"+deliveryInfo.getName()+"%"));
		}
		dc.add(Restrictions.eq(DeliveryInfo.FIELD_DEL_FLAG, DeliveryInfo.DEL_FLAG_NORMAL));
		dc.addOrder(Order.desc("id"));
		return deliveryInfoDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(DeliveryInfo deliveryInfo) {
		deliveryInfoDao.save(deliveryInfo);
	}
	
	@Transactional(readOnly = false)
	public void delete(String id) {
		deliveryInfoDao.deleteById(id);
	}

	public DeliveryInfo findByOrderId(String id) {
		return deliveryInfoDao.findByOrderId(id);
	}
	
}
